from typing import *


class Solution:
    def minOperations(self, nums: List[int]) -> int:
        q = Deque()
        ans = 0
        for v in nums:
            while q and q[-1] > v:
                q.pop()
                ans += 1
            if v != 0 and (len(q) == 0 or q[-1] < v):
                q.append(v)
        return ans + len(q)


